package com.gin.supermarket_inventory_system.inventory.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gin.database.service.MyService;
import com.gin.supermarket_inventory_system.inventory.entity.InventoryPo;

import java.util.List;

/**
 *
 * @since : 2023/10/10 14:38
 * @author : ginstone
 * @version : v1.0.0
 **/
public interface InventoryService extends MyService<InventoryPo> {

    default List<InventoryPo> listByCommodityId(long commodityId) {
        final QueryWrapper<InventoryPo> qw = new QueryWrapper<>();
        qw.eq("commodity_id", commodityId);
        return list(qw);
    }

    /**
     * 按照条码搜索库存
     * @param barcode 条码
     * @return 库存
     */
    default List<InventoryPo> listByBarcode(String barcode) {
        final QueryWrapper<InventoryPo> qw = new QueryWrapper<>();
        qw.likeRight("barcode", barcode);
        return list(qw);
    }


    /**
     * 查询指定商品id的库存数量
     * @param commodityId 商品id
     * @return 数量
     */
    default long countByCommodityId(long commodityId) {
        final QueryWrapper<InventoryPo> qw = new QueryWrapper<>();
        qw.eq("commodity_id", commodityId);
        return count(qw);
    }
}